package com.freestyle.multidatasource;

import com.freestyle.multidatasource.ext.TransactionInterceptorEx;
import com.freestyle.multidatasource.ext.TransactionProxyFactoryBeanEx;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.interceptor.TransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionInterceptor;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * Created by rocklee on 2021/12/3 12:02
 */
@Configuration
public class DataSourceConfig {
  @Resource
  private TransactionInterceptor transactionInterceptor;
  @Bean
  public DataSourceTransactionManager transactionManager(DataSource dataSource){
    DataSourceTransactionManager tsm = new DataSourceTransactionManager(dataSource);
    transactionInterceptor.setTransactionManager(tsm);
    return tsm;
  }

  /*@Bean
  public TransactionProxyFactoryBeanEx transactionProxyFactoryBean(){
    TransactionProxyFactoryBeanEx tpf=new TransactionProxyFactoryBeanEx();
    return tpf;
  }
   @Bean
  public TransactionInterceptor transactionInterceptor(PlatformTransactionManager transactionManager){
    TransactionInterceptorEx tsi=new TransactionInterceptorEx(transactionManager,(TransactionAttributeSource)null);
    return tsi;
  }*/
}
